package com.sgcc.ln.pmos.e_ln_home.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.utils.DateUtils;
import com.sgcc.ln.pmos.e_ln_home.bean.FileBean;
import com.sgcc.ln.pmos.e_ln_home.bean.InfomationListBean;

public class FileListAdapter extends BaseQuickAdapter<FileBean, BaseViewHolder> {


    private Context mContext;

    public FileListAdapter(Context context) {
        super(R.layout.item_infomationcontent);
        mContext = context;
    }

    public interface OnItemClickListener {
        //条目点击
        void itemClickListener(int position, FileBean bean);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, FileBean bean) {
        if (bean.getName().startsWith("附件")) {
            baseViewHolder.setText(R.id.tv_fileName, bean.getName());
        } else {
            baseViewHolder.setText(R.id.tv_fileName, "附件:" + bean.getName());
        }

        if("pdf".toLowerCase().equals(bean.getFileType().toLowerCase())){
            baseViewHolder.setBackgroundResource(R.id.iv_fileType,R.mipmap.pdf_icon);
        }else if ("mp4".toLowerCase().equals(bean.getFileType().toLowerCase())){
            baseViewHolder.setBackgroundResource(R.id.iv_fileType,R.mipmap.mp4_icon);
        }else if ("docx".toLowerCase().equals(bean.getFileType().toLowerCase())||"doc".toLowerCase().equals(bean.getFileType().toLowerCase())){
            baseViewHolder.setBackgroundResource(R.id.iv_fileType,R.mipmap.doc_icon);
        }else if ("jpeg".toLowerCase().equals(bean.getFileType().toLowerCase())||"jpg".toLowerCase().equals(bean.getFileType().toLowerCase())){
            baseViewHolder.setBackgroundResource(R.id.iv_fileType,R.mipmap.jpg_icon);
        }else if ("xlsx".toLowerCase().equals(bean.getFileType().toLowerCase())||"xls".toLowerCase().equals(bean.getFileType().toLowerCase())){
            baseViewHolder.setBackgroundResource(R.id.iv_fileType,R.mipmap.excel_icon);
        }

        baseViewHolder.getView(R.id.rl_file).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.itemClickListener(getItemPosition(bean), bean);
                }
            }
        });
    }


}


